package com.lpf.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

/**
 * SpringMvc 配置信息
 */
@Configuration
@EnableWebMvc    // 开启 SpringMvc 功能
@ComponentScan(basePackages = {"com.lpf.controller"})
public class WebConfig extends WebMvcConfigurerAdapter {

    // springboot 整合jsp
    // 配置视图转换器，创建 SpringMVC 视图解析器
    @Bean
    public ViewResolver viewResolver() {

        InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();

        viewResolver.setPrefix("/WEB-INF/views/");
        viewResolver.setSuffix(".jsp");

        // 可以在JSP页面中通过${}访问beans
        viewResolver.setExposeContextBeansAsAttributes(true);

        return viewResolver;
    }

}
